<html>
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></script>
        <script src="node_modules/vue/dist/vue.js"></script>
        <script src="node_modules/axios/dist/axios.js"></script>
    </head>
    <body>
        <div id="app" class="container">
            <h1>axios插件讲解</h1>
            <a href="javascript:" class="btn btn-primary" v-on:click="get">get请求</a>
            <a href="javascript:" class="btn btn-primary" @click="post">post请求</a>
            <a href="javascript:" class="btn btn-primary" @click="http">http请求</a>
            <div>{{msg}}</div>
        </div>
    </body>
    <script>
        new Vue({
            el:"#app",
            data:{
                msg:''
            },
            mounted:function(){

            },
            mounted:function(){
                axios.interceptors.request.use(function (comfig){
                    console.log("gsadjh")
                    return comfig;
                }),
                axios.interceptors.response.use(function (response){
                    console.log("response init")
                    return response;
                })
            },
            methods:{
                get:function(){
                    axios.get("/package.json",{
                        params:{
                            userId:123
                        },
                        hearders:{
                            token:"jack"
                        },
                    }).then(res=>{
                        this.msg = this.data
                    }).catch(function(error){
                       console.log("error:"+error) 
                    });
                },
                post:function(){
                    axios.post("./package.json",{
                        userId:888
                    },{
                     hearders:{
                         token:"sdhgsjhsf44244"
                     }   
                    }).then(res=>{
                        this.msg=this.data
                    })
                },
                http:function(){
                    axios({
                        url:"./package.json",
                        method:'post',
                        data:{
                            userId:123
                        },
                        params:{
                            userId:124
                        },
                        hearders:{
                            token:'123123df'
                        }
                    }).then(res=>{
                        this.msg=this.data
                    })
                }
            }
        })
    </script>
</html>